package com.zycx.common.result;

import lombok.Data;

import java.io.Serializable;

/**
 * Description:  返回结果类
 *    通用状态返回值:
 *           200 : 请求成功
 *           400 : 请求错误
 *           401 : 鉴权失败
 *           403 : 没有操作权限
 *           404 : 找不到资源
 *           500 : 服务内部错误
 * Created by zycx on 2018-12-04 21:47
 * Created with IntelliJ IDEA.
 */
@Data
public class ServerResponse<T> implements Serializable {

    /**  状态: */
    private int status;

    /** 是否请求成功 */
    private boolean success;

    /** 消息 */
    private String message;

    /** 数据 */
    private T data;

    private ServerResponse(int status,boolean success, String message, T data) {
        this.status = status;
        this.success = success;
        this.message = message;
        this.data = data;
    }

    public static <T> ServerResponse<T> success() {
        return new ServerResponse(200,true, "操作成功！", null);
    }

    public static <T> ServerResponse<T> successMessage(String message) {
        return new ServerResponse(200,true, message, null);
    }

    public static <T> ServerResponse<T> successData(T data) {
        return new ServerResponse(200,true, "操作成功！", data);
    }

    public static <T> ServerResponse<T> successMessageData(String message, T data) {
        return new ServerResponse(200,true, message, data);
    }

    public static <T> ServerResponse<T> error() {
        return new ServerResponse(200,false, "操作失败！", null);
    }

    public static <T> ServerResponse<T> errorMessage(String message) {
        return new ServerResponse(400,false, message, null);
    }

    public static <T> ServerResponse errorData(T data) {
        return new ServerResponse(400,false, "操作失败！", data);
    }

    public static <T> ServerResponse<T> errorMessageData(String message, T data) {
        return new ServerResponse(400,false, message, data);
    }

    public static <T> ServerResponse<T> errorStatusMessage(int status, String message) {
        return new ServerResponse(status,false, message, null);
    }

    public static <T> ServerResponse<T> errorStatus(int status) {
        return new ServerResponse(status,false,null, null);
    }





}
